﻿using System;
using System.Collections.Generic;
using System.Text;

namespace MatchBilingualSent
{
    public class Utility
    {
        const int MIN_ENGLISH_IN_CONTENT = 20;

        /**
         * 做最粗略的过滤
         * @return: 0 if should be filtered out; 1 if should be processed further.
         */
        static public bool filter(string strCont)
        {
            strCont = strCont.Replace(" ", "").Replace("\t", "").Replace("\n", "").Replace("\r", "");
            int eng_cnt = 0;
            for (int i = 0; i < strCont.Length - 1; i++)
            {
                if (Utility.isalpha(strCont[i]) == true &&
                    Utility.isalpha(strCont[i + 1]) == true)
                {
                    eng_cnt++;
                    if (eng_cnt >= MIN_ENGLISH_IN_CONTENT)
                    {
                        return true;
                    }
                }
            }
            if (eng_cnt >= MIN_ENGLISH_IN_CONTENT)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        static public string Formatpage(string strBuf)
        {
            int len = strBuf.Length;

            strBuf = strBuf.Replace('\r', ' ');
            strBuf = strBuf.Replace('\n', ' ');
            strBuf = strBuf.Replace('\t', ' ');

            return strBuf;
        }

        static public bool isspace(char c)
        {
            if (c == ' ' || c == '\r' || c == '\n' || c == '\t')
            {
                return true;
            }

            return false;
        }

        static public bool isalpha(char c)
        {
            if (c >= 'a' && c <= 'z')
            {
                return true;
            }

            if (c >= 'A' && c <= 'Z')
            {
                return true;
            }

            return false;
        }
    }
}
